This page last changed on Nov 23, 2006 by antoine borg.

Using the WireTap Inbound Router

The WireTap inbound router allows you to route certain events to a different endpoint as well as to the component. If you wish to copy all messages that are sent to a specific component, you just need to set the endpoint property of the WireTap router:

<inbound-router>
      <endpoint address="vm://FromUser"/>
      <router className="org.mule.routing.inbound.WireTap">
            <properties>
                  <property name="endpoint" value= "vm://tapped.channel"/>
            </properties>
      </router>
</inbound-router>

In the following scenario, I am merely copying any data from the inbound VM channel to the outbound endpoint using a BridgeComponent. However, I wish to forward some of the input based upon a filter to another component called WireTapReceiver. For simplicities' sake, I have coded this component to do nothing more than pre-pend the message with "INTERCEPTED:" before sending it to the FromTapper VM channel. The code for the WireTapReceiver is as follows:

public class WireTapReceiver {

	public String handleInterceptedData (String aMessage) {
		//Just Prepend the message with a label
		return "\nINTERCEPTED: "+aMessage;
	}
}

My Mule configuration file is setup like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mule-configuration PUBLIC "-//MuleSource //DTD mule-configuration XML V1.0//EN" "http://mule.mulesource.org/dtds/mule-configuration.dtd">

<mule-configuration id="Default" version="1.0">

<description>
      Experiment to demonstrate how the wiretap router works
</description>
<connector name="vmQueue" className="org.mule.providers.vm.VMConnector">
	<properties>
		<property name="queueEvents" value="true"/>
	</properties>
</connector>
<model name="default">
      <mule-descriptor name="StdComp" implementation="org.mule.components.simple.BridgeComponent">
            <inbound-router>
                  <endpoint address="vm://In"/>
                  <router className="org.mule.routing.inbound.WireTap">
                        <properties>
                              <property name="endpoint" value="vm://ToTapper"/>
                        </properties>
                  </router>
            </inbound-router>
            <outbound-router>
                  <router className="org.mule.routing.outbound.OutboundPassThroughRouter">
                        <endpoint address="vm://ToClient"/>
                  </router>
            </outbound-router>
      </mule-descriptor>
      <mule-descriptor name="wiretapper" implementation="org.ricston.experiments.WireTapReceiver">
            <inbound-router>
                  <endpoint address="vm://ToTapper"/>
            </inbound-router>
            <outbound-router>
                  <router className="org.mule.routing.outbound.OutboundPassThroughRouter">
                        <endpoint address="vm://FromTapper"/>
                  </router>
            </outbound-router>
      </mule-descriptor>
</model>
</mule-configuration>

The StdComp component receives events from the In endpoint. The router passes the event to the component and copies it to the vm://ToTapper endpoint too. The WireTapper component listens on this channel and forwards the event, after processing, to the FromTapper endpoint.

The WireTap router is based upon the SelectiveConsumer router and it therefore can take filters. In this example, only messages that match the filter expression are copied to the vm://ToTapper endpoint

<router className="org.mule.routing.inbound.WireTap">
      <filter className="org.mule.routing.filters.WildcardFilter" pattern="the quick brown*"/>
      <properties>
            <property name="endpoint" value="vm://tapped.channel"/>
      </properties>
</router>

Any filter that can be used with the SelectiveConsumer router can be used here too.

You can also have multiple WireTap routers, for the same component:

<inbound-router>
      <endpoint address="vm://In"/>
      <router className="org.mule.routing.inbound.WireTap">
            <filter className="org.mule.routing.filters.WildcardFilter" pattern="the quick brown*"/>
            <properties>
                <property name="endpoint" value="vm://ToTapper"/>
            </properties>
      </router>
      <router className="org.mule.routing.inbound.WireTap">
            <filter className="org.mule.routing.filters.WildcardFilter" pattern="*the slow green*"/>
            <properties>
                <property name="endpoint" value="vm://ToOtherTapper"/>
            </properties>
      </router>
</inbound-router>

As you can see input is passed to the component and also copied to one of two destinations depending on the filter.

Features

The WireTap router supports the following features:

Uses

The Wiretap router is useful both with and without filtering. If filtered, it can be used to record or take note of particular events or to copy events that require additional processing to a different component. If filters aren't used, you can take a backup copy of all events received by a component. The behaviour here is similar to that of an Interceptor but interceptors can alter the message flow by preventing the message from reaching the component. WireTap routers cannot alter message flow but just copy on demand.

References

http://svn.mule.codehaus.org/browse/mule/trunk/mule/tests/integration/src/test/resources/org/mule/test/integration/routing/wire-tap.xml?r=3468
http://mule.mulesource.org/wiki/display/MULE/Message+Routers

Document generated by Confluence on Nov 27, 2006 10:27